package com.witmore.skyline.web.controller;

import com.witmore.skyline.web.config.GlobalAccountSession;
import com.witmore.skyline.web.controller.vo.param.ProjectAddParam;
import com.witmore.skyline.web.controller.vo.param.ProjectEditParam;
import com.witmore.skyline.web.controller.vo.param.ProjectParamVO;
import com.witmore.skyline.web.controller.vo.result.AccountSession;
import com.witmore.skyline.web.controller.vo.result.ProjectResultVO;
import com.witmore.skyline.web.controller.vo.result.ResponsePageResult;
import com.witmore.skyline.web.controller.vo.result.ResponseResult;
import com.witmore.skyline.web.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
 * 项目部相关接口2.0
 * Author: 豆子高
 * Date: 2025/2/27 14:26
 */
@RestController
@RequestMapping("api/project/")
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    /**
     * 项目列表 树形结构
     */
    @GetMapping(value = "projectTreeList", name = "项目列表 树形结构")
    public ResponseResult<List<ProjectResultVO>> projectList() {
        AccountSession accountInfo = GlobalAccountSession.getUserInfo();
        return projectService.getProjectTree(accountInfo.getOrgId());
    }

    /**
     * 项目列表 树形结构（带摄像头信息不带抓拍图） V2.1
     */
    @GetMapping(value = "projectTreeWithCameraList", name = "项目列表 树形结构（带摄像头信息)")
    public ResponseResult<List<ProjectResultVO>> projectTreeWithCameraList() {
        AccountSession accountInfo = GlobalAccountSession.getUserInfo();
        return projectService.getProjectTree(accountInfo.getOrgId(), true, false);
    }

    /**
     * 项目列表 (分页)
     */
    @GetMapping(value = "projectListPage", name = "项目列表 (分页)")
    public ResponsePageResult<ProjectResultVO> projectListPage(ProjectParamVO projectParamVO) {
        AccountSession accountInfo = GlobalAccountSession.getUserInfo();
        projectParamVO.setOrgId(accountInfo.getOrgId());
        return projectService.projectListPage(projectParamVO);
    }

    /**
     * 新增项目 2.0
     */
    @PostMapping(value = "add", name = "新增项目")
    public ResponseResult<Void> add(@Valid @RequestBody ProjectAddParam param) {
        return projectService.add(param);
    }

    /**
     * 修改项目 2.0
     */
    @PostMapping(value = "edit", name = "修改项目")
    public ResponseResult<Void> edit(@Valid @RequestBody ProjectEditParam param) {
        return projectService.edit(param);
    }

    /**
     * 删除项目 2.0
     */
    @PostMapping(value = "delete", name = "删除项目")
    public ResponseResult<Void> delete(@RequestParam("id") Integer id) {
        return projectService.delete(id);
    }

}
